using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Animoso.Domain;
using Animoso.Domain.Data;

namespace Animoso.Web.Controllers
{
    public class ManageIntroductionController : ApplicationController
    {
        private IIntroductionRepository _introductionRepository;

        public ManageIntroductionController(IIntroductionRepository introductionRepository)
        {
            _introductionRepository = introductionRepository;
        }

        public ActionResult Index()
        {
            IList<Introduction> introductions = _introductionRepository.GetAll();
            return View(introductions);
        }

        public JsonResult Open()
        {
            if (!_introductionRepository.HasIntroductionByYear(DateTime.Now.Year))
            {
                Introduction introduction = new Introduction();
                introduction.Year = DateTime.Now.Year;
                introduction.CanRegister = true;
                _introductionRepository.Add(introduction);

                return Json(introduction);
            }
            return Json(false);
        }
    }
}